package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.mapper.CustomerReservationMapper;
import com.zzyl.service.impl.CustomerReservationServiceimpl;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.AppointmentTimesVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "微信客户预约管理")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationServiceimpl customerReservationServiceimpl;

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto) {
        customerReservationServiceimpl.add(reservationDto);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    private ResponseResult<ReservationDto> PaginationQuery(Integer pageNum, Integer pageSize, Integer status) {
        PageResponse<ReservationVo> pageResponse = customerReservationServiceimpl.PaginationQuery(pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancelReservation(@PathVariable("id") Long id) {
        customerReservationServiceimpl.cancelReservation(id);
        return success();
    }

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledCount() {
        Long userId = UserThreadLocal.getUserId();
        return success(customerReservationServiceimpl.getCancelledReservationCount(userId));

    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<Map<String, Object>>>countByTime(@RequestParam("time")  Long time) {
      List<Map<String, Object>>  list=customerReservationServiceimpl.countByTime(time);
        return success(list);
    }


}

